package com.five.wisdomEat.mapper;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.five.wisdomEat.entity.Application;
import org.apache.ibatis.annotations.Insert;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Update;

import java.util.List;
@Mapper
public interface ApplicationMapper extends BaseMapper<Application> {
    //查看所有申请
    @Select("SELECT a.*,e.e_name,b.* FROM application a " +
            "INNER JOIN examine e ON a.a_examineId=e.id " +
            "INNER JOIN businessinfo b ON a.a_b_number = b.b_number " +
            "ORDER BY a_time desc")
    List<Application> selectApplicationList();

    //提交申请
    @Insert("INSERT INTO application (id,a_b_number,a_examineId,a_time) " +
            "VALUES (null,#{aBNumber},1,#{aTime})")
    Integer insertApplication(Application application);

    //同意申请
    @Update("UPDATE application SET a_examineId=2 WHERE id=#{id}")
    Integer applyApplication(Application application);


    //拒绝申请
    @Update("UPDATE application SET a_examineId=3 WHERE id=#{id}")
    Integer refuseApplication(Application application);

    //查看所有未审批的商家
    @Select("SELECT COUNT(*) FROM application WHERE a_examineId = 1")
    Integer selectApplicationCount();
}
